import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ElementPlus from 'unplugin-element-plus/vite'

// https://vitejs.dev/config/
export default defineConfig({
  base: './',
  define: [
    'MODE',
    'API_BASE',
    'APP_NAME'
  ].reduce((t, k) => ({ ...t, [`process.env.${k}`]: JSON.stringify(process.env[k]) }), {}),
  resolve: {
    alias: {
      '~/': `${path.resolve(__dirname, 'src')}/`
    }
  },
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@use "~/assets/theme/default.scss" as *;`
      }
    }
  },
  plugins: [
    vue(),
    ElementPlus({ useSource: true })
  ],
  server: {
    proxy: (() => {
      const proxyHost = '192.168.233.201:7861'
      return {
        '/api': {
          target: `http://${proxyHost}`,
          changeOrigin: true,
          rewrite: path => path.replace(/^\/api/, '')
        }
      }
    })()
  }
})
